package com.lzj.admin.controller;


import com.lzj.admin.model.RespBean;
import com.lzj.admin.pojo.Area;
import com.lzj.admin.query.AreaQuery;
import com.lzj.admin.service.IAreaService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 村信息表 前端控制器
 * </p>
 *
 * @author luoyoumou
 * @date 2022-12-08
 * @version 1.0
 */
@Controller
@RequestMapping("/area")
public class AreaController {

    @Resource
    private IAreaService areaService;


    /**
     * 村管理主页
     * @return
     */
    @RequestMapping("index")
    public String index(){
        return "area/area";
    }


    /**
     * 村列表查询接口
     * @param areaQuery
     * @return
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> areaList(AreaQuery areaQuery){

        return areaService.areaList(areaQuery);
    }


    @RequestMapping("/allArea")
    @ResponseBody
    public List<Area> allArea(){
        return areaService.list();
    }

    /**
     * 添加|更新 村页
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("addOrUpdateAreaPage")
    public String addOrUpdateAreaPage(Integer id, Model model){
        if(null != id){
            model.addAttribute("area",areaService.getById(id));
        }
        return "area/add_update";
    }


    /**
     * 村添加
     * @param area
     * @return
     */
    @RequestMapping("save")
    @ResponseBody
    public RespBean saveArea(Area area){
        areaService.saveArea(area);
        return RespBean.success("村记录添加成功！");
    }


    /**
     * 村更新
     * @param area
     * @return
     */
    @RequestMapping("update")
    @ResponseBody
    public RespBean updateArea(Area area){
        areaService.updateArea(area);
        return RespBean.success("村记录更新成功！");
    }


    /**
     * 村删除
     * @param id
     * @return
     */
    @RequestMapping("delete")
    @ResponseBody
    public RespBean deleteArea(Integer id){
        areaService.deleteArea(id);
        return RespBean.success("村记录删除成功！");

    }


}
